Ext.BLANK_IMAGE_URL = './extjs/resources/themes/images/default/tree/s.gif';
Ext.application({
    name: 'Zm',
    uses: [
        'Ext.state.Manager',
        'Zm.state.HttpProvider',
        'Zm.controller.Login',
        'Zm.controller.NavTree',
        'Zm.controller.DevTree',
        'Zm.controller.Property',
        'Zm.controller.DevDef',
        'Zm.controller.X3d',
        'Zm.controller.Lines',
        'Zm.controller.Tour',
        'Zm.controller.Data',
        'Zm.controller.User',
        'Zm.controller.Chart',
		'Zm.view.Viewport',
        'Zm.i18n.CN',
        'Zm.Common'
    ],
    launch: function() {
        var me = this,
            lang = Zm.i18n.Lang;
        Zm.i18n.CN.trans(); //to chinese
        Ext.apply(Ext.form.field.VTypes,{
            password: function(val, field) {
                if(field.rePassField) {
                    var pwd = field.up('form').down('#' + field.rePassField);
                    return (val == pwd.getValue());
                }
                return true;
            },
            passwordText:lang.tReErr
        });
        
        if(g_user == null){
            me.initLogin();
        }else{
            me.initMain();
        }
    },
    sc:function(){//开始Controller
        for(var i=0;i<arguments.length;i++){
            this.getController(arguments[i]);//.init();
        }        
    },
    initLogin: function(){
        this.sc('Login');
        Ext.widget('login');
    },
    initMain: function(){
        var me = this,lang = Zm.i18n.Lang,el = Ext.getBody();
        el.mask(lang.loadText);
        Ext.state.Manager.setProvider(new Zm.state.HttpProvider({
            readUrl:g_app+'/Viewstate/read',
            saveUrl:g_app+'/Viewstate/save',
            listeners:{
                readfailure:me.initGui,
                readsuccess:me.initGui,
                scope:me
            }
        }));
    },
    initGui: function(){
		var me = this,
            el = Ext.getBody(),
            nav;
        me.sc('NavTree','DevTree','Property','DevDef','X3d','Lines','Tour','Data','User','Chart');
		Ext.create('Zm.view.Viewport');
        el.unmask();
    }
});
